//
// Created by CodeZijun on 2022/12/9.
//

#include "Graph.h"
//无向图邻接矩阵
void Graph::udCreateGraphAdjMatrix() {
    cout<<"请输入顶点,以-1结束"<<endl;
    int tmp;
    while(true){
        cin>>tmp;
        if(tmp == -1)
            break;
        else
            adjMat->vertex[tmp] = adjMat->cnt++;
    }
    cout<<"请输入无向边，以-1结束"<<endl;
    int i,j;
    int weight;
    while(true){
        cin>>i;
        if(i == -1)
            break;
        else{
            cin>>j>>weight;
            adjMat->matrix[adjMat->vertex.find(i)->second][adjMat->vertex.find(j)->second] = weight;
            adjMat->matrix[adjMat->vertex.find(j)->second][adjMat->vertex.find(i)->second] = weight;
        }
    }
}

//有向图邻接矩阵
void Graph::dCreateGraphAdjMatrix() {
    cout<<"请输入顶点，以-1结束"<<endl;
    int tmp;
    while(true){
        cin>>tmp;
        if(tmp == -1)
            break;
        else
            adjMat->vertex[tmp] = adjMat->cnt++;
    }
    cout<<"请输入有向边，以-1结束"<<endl;
    int i,j;
    int weight;
    while(true){
        cin>>i;
        if(i == -1)
            break;
        else{
            cin>>j>>weight;
            adjMat->matrix[adjMat->vertex.find(i)->second][adjMat->vertex.find(j)->second] = weight;
        }
    }
}

//输出图的邻接矩阵
void Graph::printAdjMatrix() {
    for(int i = 0 ; i<adjMat->cnt ; i++){
        for(int j = 0 ; j<adjMat->cnt ; j++) {
            if (adjMat->matrix[i][j] == INF)
                cout << '#' << " ";
            else
                cout << adjMat->matrix[i][j] << " ";
        }
        cout<<endl;
    }
}

//邻接表
void Graph::createGraphAdjList() {
    int tmp;
    cout<<"请输入顶点，以-1结束"<<endl;
    while(true){
        cin>>tmp;
        if(tmp == -1)
            break;
        else
            adjL->insertVertex(tmp);
    }
    cout<<"请输入边，以-1结束"<<endl;
    int i,j,weight;
    while(true){
        cin>>i;
        if(i == -1)
            break;
        else{
            cin>>j>>weight;
            adjL->insertArc(i,j,weight);
        }
    }
}
//十字链表
void Graph::createOrtList() {
    int tmp;
    cout<<"请输入顶点，以-1结束"<<endl;
    while(true){
        cin>>tmp;
        if(tmp == -1)
            break;
        else
            ortL->insertVertex(tmp);
    }
    cout<<"请输入边，以-1结束"<<endl;
    while(true){
        int i,j,w;
        cin>>i;
        if(i == -1)
            break;
        else{
            cin>>j>>w;
            ortL->insertArc(i,j,w);
        }
    }
}

//邻接多重表
void Graph::createMAdjList() {
    int tmp;
    cout<<"请输入节点，以-1结束"<<endl;
    while(true){
        cin>>tmp;
        if(tmp == -1)
            break;
        else
            mAdjL->insertVertex(tmp);
    }
    cout<<"请输入边，以-1结束"<<endl;
    while(true){
        int i;
        cin>>i;
        if(i == -1)
            break;
        else{
            int j,w;
            cin>>j>>w;
            mAdjL->insertArc(i,j,w);
        }
    }
}
